package org.apache.catalina.core;



public class TenantContext{
	
    static ThreadLocal<TenantContext> local = new ThreadLocal<TenantContext>();

    String tenantId;
		private String getTenantId() {
			return tenantId;
		}
		private void setTenantId(String tenantId) {
			this.tenantId = tenantId;
		}


	protected TenantContext(String tenantId){
//		if(getThreadLocalInstance()!=null)
//			throw new RuntimeException("There's uncommitted transactionContext remains.");
		
		this.tenantId = tenantId;
		
//new Throwable("TenantId is recognized: " + tenantId).printStackTrace();
		
		local.set(this);

	}
	
	
	public static TenantContext getThreadLocalInstance(){
		TenantContext tc = local.get();
		
		return tc;
	}

	public static String getCurrentThreadTenantId(){
		if(getThreadLocalInstance()==null) return null;
		
		return getThreadLocalInstance().getTenantId();
	}
	
}